From f0dc96dc71bd2dfe03ddb9ada247d133d5de6f6d Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Thu, 1 May 2008 09:55:06 +0100 Subject: [PATCH] [Xend/ACM] Embed the policy schema in the python file This patch embeds the ACM policy's schema in the python file where the schema is being accessed for verifying the policy XML. This way also programs that cannot access a protected directory where the schema may be located in can use this class. Signed-off-by: Stefan Berger --- tools/python/xen/util/acmpolicy.py | 163 ++++++++++++++++++++++++++--- 1 file changed, 149 insertions(+), 14 deletions(-) diff --git a/tools/python/xen/util/acmpolicy.py b/tools/python/xen/util/acmpolicy.py index f0f5601a8c..b7ccb194b5 100644 --- a/tools/python/xen/util/acmpolicy.py +++ b/tools/python/xen/util/acmpolicy.py @@ -49,8 +49,6 @@ ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2 ACM_POLICY_UNDEFINED = 15 -ACM_SCHEMA_FILE = ACM_POLICIES_DIR + "security_policy.xsd" - ACM_LABEL_UNLABELED = "__UNLABELED__" ACM_LABEL_UNLABELED_DISPLAY = "unlabeled" @@ -118,6 +116,153 @@ DEFAULT_policy = \ " \n" +\ "\n" +ACM_SCHEMA=""" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +""" + def get_DEFAULT_policy(dom0label=""): fromnode = "" @@ -133,18 +278,7 @@ def initialize(): instdir = security.install_policy_dir_prefix DEF_policy_file = "DEFAULT-security_policy.xml" - xsd_file = "security_policy.xsd" - - files = [ xsd_file ] - for file in files: - if not os.path.isfile(policiesdir + "/" + file ): - try: - shutil.copyfile(instdir + "/" + file, - policiesdir + "/" + file) - except Exception, e: - log.info("could not copy '%s': %s" % - (file, str(e))) #Install default policy. f = open(policiesdir + "/" + DEF_policy_file, 'w') if f: @@ -219,7 +353,8 @@ class ACMPolicy(XSPolicy): log.warn("Libxml2 python-wrapper is not installed on the system.") return xsconstants.XSERR_SUCCESS try: - parserctxt = libxml2.schemaNewParserCtxt(ACM_SCHEMA_FILE) + parserctxt = libxml2.schemaNewMemParserCtxt(ACM_SCHEMA, + len(ACM_SCHEMA)) schemaparser = parserctxt.schemaParse() valid = schemaparser.schemaNewValidCtxt() doc = libxml2.parseDoc(self.toxml()) -- 2.30.2